# -*- coding: utf-8 -*-
import os
from liberHook.BaseHook import BaseHook
from liberLibs import utils


class Hook(BaseHook):
    def __init__(self, library, directory, ext, start, end):
        BaseHook.__init__(self, library, directory, ext, start, end)

    def execute(self):
        files = self.files
        if not files:
            self.append_error("No file found.")
            return
        temp_file = utils.temp_file("liber_rv_list.json")
        if not os.path.isfile(temp_file):
            utils.write_json(temp_file, self.files)
        else:
            json_data = utils.read_json(temp_file)
            json_data.extend(self.files)
            utils.write_json(temp_file, json_data)
